<template>
  <div class="couponLis">
    <div class="shopCoupon" v-for="(item, index) in coupon" :key="index" @click.stop="goDetail(item)">
      <van-swipe-cell>
        <div class="shopCouponNew">
          <div class="left">
            <div class="postLeft" :style="{ backgroundImage: `url(https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/couponsbg_${types}.png)` }">
              <template v-if="item.belongs_to_coupon && item.belongs_to_coupon.coupon_method == 1">
                <span class="textOne" :style="{ fontSize: item.belongs_to_coupon.deduct.length > 9 ? '0.7rem' : '' }"> {{ $i18n.t("money") }}{{ item.belongs_to_coupon.deduct }} </span>
                <div class="line"></div>
                <span class="textTwo">满{{ item.belongs_to_coupon.enough }}可用</span>
              </template>
              <template v-if="item.belongs_to_coupon && item.belongs_to_coupon.coupon_method == 2">
                <span class="textOne">{{ $i18n.t("money") }}{{ item.belongs_to_coupon.discount }}折</span>
                <div class="line"></div>
                <span class="textTwo">满{{ item.belongs_to_coupon.enough }}立享</span>
              </template>
            </div>
          </div>
          <div class="right">
            <div class="right_top">
              <div class="right_top_text">
                <div :class="`baground_${types}`">{{ item.belongs_to_coupon && item.belongs_to_coupon.coupon_type_name }}</div>
                <template v-if="item.combine && item.num != 1">
                  <span>{{ item.num }}张</span>
                </template>
              </div>
            </div>
            <div class="right_top_bottom_text">
              {{ item.belongs_to_coupon && item.belongs_to_coupon.name }}
            </div>
            <div class="right_bottom">{{ item.time_start }}-{{ item.time_end }}</div>
            <div class="dueBox" v-if="item.near_expiration == 1">快过期</div>
          </div>
        </div>
        <template #right>
          <van-button square type="danger" text="删除" style="height: 100%;" @click="delteteItem(item, index)" />
        </template>
      </van-swipe-cell>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    coupon: {
      type: null
    },
    types: {
      type: null
    },
    combine_show: {
      type: null
    }
  },
  data() {
    return {};
  },
  methods: {
    goDetail(data) {
      let that = this;
      this.$router.push(
        this.fun.getUrl("coupon_v2_detail", {
          id: data.id,
          combine_show: that.combine_show,
          combine: data.combine
        })
      );
    },
    delteteItem(item, i) {
      let that = this;
      console.log(this.coupon);
      let json = {
        id: item.id,
        i: this.fun.getKeyByI(),
        type: this.fun.getTyep()
      };

      $http.get("coupon.member-coupon.delete", json, "处理中...").then(
        response => {
          if (response.result == 1) {
            this.coupon.splice(i, 1);
            let arr = this.coupon;
            let num = 0;
            arr.forEach(element => {
              num += element.num
            });
            this.$emit("updateDelete", num);
            that.$dialog.alert({ message: "操作成功" });
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          console.log(response);
        }
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.couponLis {
  padding-top: 0.9rem;
}
.shopCouponNew {
  width: 21.66rem;
  height: 6.75rem;
  display: flex;
}
.shopCoupon {
  margin: 0 0.91rem 0 0;
  width: 21.66rem;
  box-shadow: 0.03rem 0.12rem 0.44rem -0.29rem rgba(81, 81, 81, 0.52);
  position: relative;
  margin-bottom: 1rem;

  .left {
    flex: 1;
    height: 6.75rem;
    position: relative;

    .postLeft {
      position: absolute;
      right: -4px;
      top: 0;
      width: 8.28rem;
      height: 6.81rem;
      background-repeat: no-repeat;
      background-size: cover;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      // background-image: url('https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/couponsbg_1.png');
      .line {
        width: 6.375rem;
        border: dashed 0.043rem #f5f5f5;
        margin-left: 0.6rem;
      }

      .Chapter_number {
        font-size: 0.6rem;
        color: #fff;
        position: absolute;
        top: 0.36rem;
        left: 0.6rem;
        width: 2rem;
        text-align: center;
      }

      .textOne {
        font-size: 1.63rem;
        color: #fff;
        margin-top: 0.8rem;
        // margin-left: 0.6rem;
        margin-bottom: 0.6rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 100%;
        padding-left: 0.5rem;
      }

      .textTwo {
        font-size: 0.69rem;
        line-height: 0.84rem;
        color: #fff;
        margin-top: 0.72rem;
        margin-bottom: 0.5rem;
      }

      .tapBox {
        width: 4.66rem;
        height: 1.34rem;
        background-color: #fff;
        border-radius: 0.43rem;
        line-height: 1.44rem;

        span {
          color: #fba560;
          font-size: 0.79rem;
          letter-spacing: 0.08rem;
        }
      }
    }
  }

  .right {
    width: 13.94rem;
    height: 6.75rem;
    padding: 0 0.69rem 0 1rem;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;

    .dueBox {
      font-size: 0.68rem;
      width: 5rem;
      height: 1.2rem;
      position: absolute;
      right: -21px;
      top: 12px;
      transform: rotate(45deg);
      background: #42a354;
      color: #fff;
      letter-spacing: 0.1rem;
      line-height: 1.2rem;
      text-align: center;
    }

    .isdueBox {
      font-size: 0.91rem;
      width: 6rem;
      height: 1.8rem;
      position: absolute;
      right: -29px;
      top: 7px;
      transform: rotate(45deg);
      background: #cecece;
      color: #000;
      letter-spacing: 0.1rem;
      line-height: 1.8rem;
      text-align: center;
    }

    .right_top {
      width: 100%;
      display: flex;
      flex-direction: column;
      padding-top: 0.56rem;

      .right_top_text {
        display: flex;
        align-items: center;

        div {
          // background-color: #fbbd5c;
          border-radius: 0.22rem;
          // width: 3.69rem;
          height: 1.25rem;
          margin-right: 0.53rem;
          font-size: 0.71rem;
          color: #fff;
          display: flex;
          justify-content: center;
          align-items: center;
          padding: 0 0.5rem;
        }

        span {
          font-size: 0.816rem;
          color: #f15a5a;
          border: solid 0.094rem #ff5d5d;
          border-radius: 0.313rem;
          height: 1.25rem;
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 0 0.5rem;
        }
      }
    }

    .right_top_bottom_text {
      margin-top: 0.625rem;
      margin-bottom: 0.6rem;
      text-align: left;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }

    .right_bottom {
      text-align: left;
      color: #9c9c9c;
      font-size: 0.6rem;
    }
    .right_bottom_spread {
      text-align: left;
      color: #000;
      font-size: 0.6rem;
      display: flex;
      align-items: center;
      .txt {
        margin-right: 0.25rem;
      }
    }
  }

  .coupon_voucher_btm {
    display: none;
    position: relative;
    box-sizing: border-box;
    padding: 0.5rem 0.625rem;
    background-color: #f2f2f7;
    border-radius: 0.1875rem;

    .coupon_voucher_explain {
      color: #999;
      font-size: 12px;
      text-align: left;
    }
  }

  .coupon_voucher_btm.hies {
    display: block;
  }
}
.baground_4 {
  background-color: #6dccf8;
}

.baground_6 {
  background-color: #fb946c;
}

.baground_1 {
  background-color: #fbbd5c;
}

.baground_5 {
  background-color: #6dccf8;
}

.baground_3 {
  background-color: #a291ff;
}

.baground_2 {
  background-color: #fc6d6d;
}

.baground_8 {
  background-color: #3c98ff;
}
</style>
